<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up()
  {
    Schema::create('users', function (Blueprint $table) {
      $table->id();
      $table->string('username')->unique();
      $table->enum('role', ['member', 'admin', 'seller', 'agent'])->default('member');
      $table->foreignId('pid')->nullable();
      $table->string('avatar')->nullable();

      $table->string('code')->nullable();
      $table->string('remark')->nullable();
      $table->string('mobile')->nullable();
      $table->unsignedDecimal('coins', 16, 3)->default(0);
      $table->unsignedDecimal('cut', 10, 3)->default(0);
      // $table->unsignedInteger('coins')->default(0);
      $table->unsignedDecimal('fee_ratio', 5, 3)->default(0);
      $table->unsignedDecimal('tip')->default(0);

      $table->text('perms')->nullable();
      $table->string('realname')->nullable();

      // $table->string('email')->unique();
      // $table->timestamp('email_verified_at')->nullable();
      $table->string('password')->nullable();
      $table->string('security')->nullable();
      $table->string('api_token')->nullable();
      $table->string('google_secret')->nullable();
      $table->tinyInteger('google_auth_enable')->default(0)->comment('0禁用；1启用');
      $table->string('notify_url')->nullable();
      $table->unsignedInteger('freeze_minutes')->nullable()->comment('下级用户接单点击完成后的解冻时间');
      $table->rememberToken();
      $table->timestamp('login_at')->nullable();
      $table->string('login_ip')->nullable();
      $table->tinyInteger('enable')->default(1)->comment('0禁用；1启用');
      $table->timestamps();
    });
  }

  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down()
  {
    Schema::dropIfExists('users');
  }
}
